package com.killer.util;


public class HttpProtocolUtil {

    /**
     * 获取响应code为200时的响应头
     * @param dataLength
     * @return
     */
    public static String getRep200Header(int dataLength){
        return "HTTP/1.1 200 OK"+ System.getProperty("line.separator")
                +"Content-Length: " + dataLength + System.getProperty("line.separator")
                + "Content-Type: text/html;charset=utf-8"+ System.getProperty("line.separator")
                //响应头和响应体需要再加一个换行
                +System.getProperty("line.separator");
    }

    /**
     * 获取相应code为500时的响应头
     * @param dataLength
     * @return
     */
    public static String getRep500Header(int dataLength){
        return "HTTP/1.1 500 SERVER ERROR"+ System.getProperty("line.separator")
                +"Content-Length: " + dataLength + System.getProperty("line.separator")
                + "Content-Type: text/html;charset=utf-8"+ System.getProperty("line.separator")
                //响应头和响应体需要再加一个换行
                +System.getProperty("line.separator");
    }

    /**
     * 获取相应code为404时的响应头
     */
    public static String getRep404Header(){
        String data = "Not Found";
        return "HTTP/1.1 404 NOT FOUND"+ System.getProperty("line.separator")
                +"Content-Length: " + data.getBytes().length + System.getProperty("line.separator")
                + "Content-Type: text/html;charset=utf-8"+ System.getProperty("line.separator")
                //响应头和响应体需要再加一个换行
                +System.getProperty("line.separator")+data;
    }

}
